/**
 * Scala中的类
 * 面向对象：封装、继承、多态
 * 也可以定义属性、方法
 * {}默认的构造方法
 */
class Demo03StudentScala(id: String, name: String, age: Int) {

  // 定义属性即赋值
  val _id: String = id
  val _name: String = name
  val _age: Int = age
  var _clazz: String = _ // 待会再赋值
  //  var _clazz: String = "自由分班" // 给默认值

  // 重载构造方法
  def this(id: String, name: String, age: Int, clazz: String) {
    // 第一行代码必须调用默认的构造方法
    this(id, name, age)
    println("重载构造方法")

    this._clazz = clazz
  }

  override def toString(): String = {
    return s"Demo03StudentScala(id=${_id},name=${_name},age=${_age})"
  }

  def printStuName(): Unit = {
    println(_name)
  }

  def printClazz(): Unit = {
    println(this._clazz)
  }

}


object Demo03StudentScala {
  def main(args: Array[String]): Unit = {
    // 创建对象
    val zs: Demo03StudentScala = new Demo03StudentScala("001", "zs", 20)
    val ls: Demo03StudentScala = new Demo03StudentScala("002", "ls", 22)
    println(zs)
    println(ls)
    println(zs._name)

    zs.printStuName()
    ls.printStuName()

    val ww: Demo03StudentScala = new Demo03StudentScala("003", "ww", 22)
    val xm: Demo03StudentScala = new Demo03StudentScala("004", "xm", 21, "文科二班")

    ww.printClazz()
    xm.printClazz()


  }
}
